const a = function (echarts, d, { xe: { commafy, get, pluck } }) {
  const items = get(d, "data.items", []);
  if (!items.length) return {};
  console.log("chart data: ", items);
  items.forEach((i) => {
    i.ys = ((i.ys || 0) / 10000).toFixed(2);
    i.zc = ((i.zc || 0) / 10000).toFixed(2);
    i.zxl = ((i.zxl || 0) * 100).toFixed(1);
  });
  return {
    tooltip: {
      trigger: "axis",
      axisPointer: { type: "shadow", label: { backgroundColor: "#283b56" } },
    },
    legend: {},
    grid: { containLabel: true, top: 80, left: 20, right: 10, bottom: 20 },
    xAxis: {
      type: "category",
      boundaryGap: true,
      data: pluck(items, "programName"),
      axisLabel: {
        interval: 2,
      },
    },
    yAxis: [
      {
        type: "value",
        scale: true,
        name: "单位: 万元",
        nameTextStyle: { align: "right" },
      },
      {
        type: "value",
        scale: true,
        name: "单位: %",
        nameTextStyle: { align: "right" },
      },
    ],
    series: [
      {
        name: "预算",
        label: { show: true, position: "top" },
        barGap: "80%",
        barCategoryGap: "30%",
        type: "bar",
        stack: "ys",
        data: pluck(items, "ys"),
        yAxisIndex: 0,
      },
      {
        name: "支出",
        label: { show: true, position: "top" },
        barGap: "80%",
        barCategoryGap: "30%",
        type: "bar",
        stack: "zc",
        data: pluck(items, "zc"),
        yAxisIndex: 0,
      },
      {
        name: "执行率",
        label: { show: true, position: "top" },
        barGap: "80%",
        barCategoryGap: "30%",
        type: "bar",
        stack: "zxl",
        data: pluck(items, "zxl"),
        yAxisIndex: 1,
      },
    ],
    tooltip: {
      trigger: "axis",
      extraCssText: "white-space:pre-wrap;",
      formatter: function (params) {
        console.log("params", params);
        let result = params[0].name + "\n";
        for (let i = 0; i < params.length; i++) {
          let seriesName = params[i].seriesName;
          let value = params[i].value;
          let unit = "";
          if (seriesName === "执行率") {
            unit = "%";
          } else {
            unit = "万元";
          }
          result += seriesName + ": " + value + unit + "\n";
        }
        console.log("result", result);
        return result;
      },
    },
  };
};
